﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
using SMS.Fady_HanyDbDataSetTableAdapters;

namespace SMS.Reports
{
    public partial class OrderReport : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Unnamed2_Click(object sender, EventArgs e)
        {
            Report.LocalReport.DataSources.Clear();
            OrderItemTableAdapter ad = new OrderItemTableAdapter();

            Report.LocalReport.DataSources.Add(
                new ReportDataSource("OrderItem", ad.GetData(int.Parse(Request.QueryString["ID"])).ToList()));
            SMS.Business.OrderBusiness OB = new Business.OrderBusiness();
            SMS.DAL.Order Or = OB.GetByID((int.Parse(Request.QueryString["ID"])));


            Report.LocalReport.SetParameters(new ReportParameter("OrderID", Request.QueryString["ID"]));
            Report.LocalReport.SetParameters(new ReportParameter("Date", DateTime.Now.ToString()));
            Report.LocalReport.SetParameters(new ReportParameter("StockName", Or.StockUser.Stock.Name));
            Report.LocalReport.SetParameters(new ReportParameter("Worker", Or.StockUser.User.UserName));
            Report.LocalReport.SetParameters(new ReportParameter("CustomerName", Or.Customer.Name));
            Report.LocalReport.SetParameters(new ReportParameter("DiscountRate", Or.DiscountAmount.ToString()));
            Report.LocalReport.SetParameters(new ReportParameter("Paied", Or.PaidPrice.ToString()));
            Report.LocalReport.SetParameters(new ReportParameter("FinalAmount", Or.DiscountAmount == 0 ? Or.TotalPrice.ToString() : ((Or.TotalPrice - (Or.TotalPrice / 100) * Or.DiscountAmount)).ToString()));
            Report.LocalReport.SetParameters(new ReportParameter("Type", GetTypeString(Or.Type)));
            Report.DataBind();
        }

        private string GetTypeString(int? nullable)
        {
            switch (nullable)
            {
                case 0:
                    return "بيع";
                case 1:
                    return "شراء";
                default:
                    return string.Empty;
            }
        }
    }
}